<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml"
	xmlns:h="http://xmlns.jcp.org/jsf/html"
	xmlns:f="http://xmlns.jcp.org/jsf/core"
	xmlns:ui="http://xmlns.jcp.org/jsf/facelets"
	xmlns:c="http://xmlns.jcp.org/jsf/composite"
	xmlns:p="http://primefaces.org/ui">

<ui:decorate template="/jsp/WEB/pageLayout.xhtml">
	<ui:define name="centro">
		<h:form id="form">
			<h:outputScript name="calendario_pt_BR.js" library="js" />
			<p:panel id="CadLista" header="Cadastro Lista de Preços">
				<f:facet name="actions">
					<h:commandLink
						styleClass="ui-panel-titlebar-icon ui-corner-all ui-state-default" title="Ajuda"
						onclick="dlg1.show(); return false;">
						<h:outputText styleClass="ui-icon ui-icon-help" />
					</h:commandLink>
				</f:facet>

				<p:dialog header="Ajuda" widgetVar="dlg1">
					<h:outputText value="#{ListaPrecoBean.help1}" escape="false" />
				</p:dialog>

				<!-- ############################################################ -->
				<!-- Painel para cadastro -->
				<!-- ############################################################ -->

				<p:growl id="msgs" showDetail="true" />
				<p:focus for="Nome" />
				<h:panelGrid id="gridLista" columns="2" cellspacing="4">

					<h:outputLabel value="Nome:" styleClass="dlgTitulo" />
					<p:inputText id="Nome"
						value="#{ListaPrecoBean.priceListEntity.name}" />

					<h:outputLabel for="popup" value="Data inicial:" />
					<p:calendar id="popup"
						value="#{ListaPrecoBean.priceListEntity.initialDate}"
						pattern="dd/MM/yyyy" locale="pt_BR"
						title="Campo obrigatório. Informe a data inicial" />

					<h:outputLabel for="popup2" value="Data final:" />
					<p:calendar id="popup2"
						value="#{ListaPrecoBean.priceListEntity.finalDate}"
						pattern="dd/MM/yyyy" locale="pt_BR"
						title="Campo obrigatório. Informe a data final" />

				</h:panelGrid>

				<p:commandButton id="btnSalvar" value="Adicionar" update="@form"
					ajax="false" icon="ui-icon-disk"
					action="#{ListaPrecoBean.salvarLista()}" style="margin-top:2%" />

				<p:commandButton value="Limpar" update="@form" resetValues="true"
					action="#{ListaPrecoBean.refresh()}" immediate="true"
					icon="ui-icon-document" style="margin-top:2%">
				</p:commandButton>
			</p:panel>
			<p:separator style="margin-top:3%" />

			
			
			
			<p:fieldset legend="Relatório de Lista Cadastrada / Cadastro de Itens da Lista" toggleable="true" toggleSpeed="500">
				<p:ajax event="toggle"/>
				<h:outputText value="Para cadastrar preço aos produtos, basta clicar no ícone  '+'  abaixo." />
				<f:facet name="actions">
					<h:commandLink
						styleClass="ui-panel-titlebar-icon ui-corner-all ui-state-default" title="Ajuda"
						onclick="dlg2.show(); return false;">
						<h:outputText styleClass="ui-icon ui-icon-help" />
					</h:commandLink>
				</f:facet>

				<p:dialog header="Ajuda" widgetVar="dlg2">
					<h:outputText value="#{ListaPrecoBean.help2}" escape="false" />
				</p:dialog>

				<!-- ############################################################ -->
				<!-- Grid das listas cadastradas -->
				<!-- ############################################################ -->
				<p:dataTable id="tabelaDetail"
					value="#{ListaPrecoBean.lstPriceListEntity}" var="listaPreco"
					rowIndexVar="rowIndex" emptyMessage="Nenhum registro encontrado!"
					style="margin-top:30px; position: auto" paginator="true" rows="5">

					<p:column style="width: 25px;" sortBy="idList">
						<f:facet name="header">Código</f:facet>
						<h:outputText value="#{listaPreco.idList}" />
					</p:column>

					<p:column style="width: 50px;" sortBy="name">
						<f:facet name="header">Nome</f:facet>
						<h:outputText value="#{listaPreco.name}" />
					</p:column>

					<p:column style="width: 50px;" sortBy="initialDate">
						<f:facet name="header">Data inicial</f:facet>
						<h:outputText value="#{listaPreco.initialDate}">
							<f:convertDateTime locale="pt_BR" pattern="dd/MM/yyyy" />
						</h:outputText>
					</p:column>

					<p:column style="width: 50px;" sortBy="finalDate">
						<f:facet name="header">Data final</f:facet>
						<h:outputText value="#{listaPreco.finalDate}">
							<f:convertDateTime locale="pt_BR" pattern="dd/MM/yyyy" />
						</h:outputText>
					</p:column>

					<p:column style="width: 10px">
						<f:facet name="header">Preço</f:facet>
						<p:commandButton id="selectButtons" image="ui-icon-plus"
							action="#{CadListaPrecoItensBean.carregaGridProdutos()}"
							update=":form1" oncomplete="PF('listaPrecoDialog').show()"
							title="Incluir valores">
							<f:setPropertyActionListener value="#{listaPreco.idList}"
								target="#{CadListaPrecoItensBean.idLista}" />
						</p:commandButton>
					</p:column>

				</p:dataTable>
				</p:fieldset>
		</h:form>

		<!-- ############################################################ -->
		<!-- Dialog - Tela para Adição de Preços -->
		<!-- ############################################################ -->
		<h:form id="form1">
			<p:dialog id="listaDlg" widgetVar="listaPrecoDialog"
				resizable="false" showEffect="fade" hideEffect="explode"
				header="Inserir valor de produtos" >
				<h:panelGrid columns="1" cellpadding="3" style="border: 0px;">

					<p:dataTable id="tabelaProd"
						value="#{CadListaPrecoItensBean.lstItensGrid}" var="produto"
						rowIndexVar="rowIndex" emptyMessage="Nenhum registro encontrado"
						style="margin-top:10px; position: auto" paginator="true" rows="10">

						<p:column style="width: 30px;" sortBy="productId">
							<f:facet name="header">Cód.</f:facet>
							<h:outputText value="#{produto.id}" />
						</p:column>

						<p:column style="width: 100px;" sortBy="descrMerchandise">
							<f:facet name="header">Descrição</f:facet>
							<h:outputText value="#{produto.decr}" />
						</p:column>

						<p:column headerText="Valor (R$)" style="width: 30px;"
							sortBy="valor">
							<h:inputText id="valor" style="float:right"
								value="#{produto.valor}">
								<f:convertNumber locale="pt_BR" currencyCode="BRL"
									minFractionDigits="2" />
							</h:inputText>
						</p:column>

					</p:dataTable>

					<h:panelGrid columns="2" cellpadding="4" style="border: 0px;">
						<p:commandButton id="btnSalvar" value="Salvar" update="form1"
							ajax="false" icon="ui-icon-disk"
							action="#{CadListaPrecoItensBean.salvarItens()}">
						</p:commandButton>

						<p:commandButton id="btnSair" value="Sair" update="@form1"
							ajax="false" resetValues="true" title="Retorna para Lista de Preço"
								action="#{CadListaPrecoItensBean.limparTela()}" immediate="true"
							icon="ui-icon-document">
						</p:commandButton>

					</h:panelGrid>

				</h:panelGrid>
			</p:dialog>
		</h:form>
	</ui:define>
</ui:decorate>

</html>